<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>按符号重拍数组</title>
</head>

<body>
  <script>
    var rearrangeArray = function (nums) {
      let arr = new Array(nums.length), a = 0, b = 0
      nums.forEach(v => {
        if (v >= 0) {
          arr[a * 2] = v
          a++
        } else {
          arr[b * 2 + 1] = v
          b++
        }
      })
      return arr
    };
    console.log(rearrangeArray([3, 1, -2, -5, 2, -4]))

  </script>
</body>

</html>